package com.office.personalOffice.personalInfo.controller;

import com.office.personalOffice.personalInfo.model.TbStaff;
import com.office.personalOffice.personalInfo.service.impl.PersonalInfoService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/PersonalInfo")
public class PersonalInfoAction {

    @Autowired
    private PersonalInfoService personalInfoService;

    public PersonalInfoService getPersonalInfoService() {
        return personalInfoService;
    }

    public void setPersonalInfoService(PersonalInfoService personalInfoService) {
        this.personalInfoService = personalInfoService;
    }

    //页面打开渲染数据
    @ResponseBody
    @RequestMapping("/getSelfInfo")
    public TbStaff getSelfInfo(TbStaff Staff,HttpSession session){
        TbStaff tbStaff =(TbStaff)session.getAttribute("loginUser");
        TbStaff staffByCondition = personalInfoService.getStaffByCondition(tbStaff);
        return staffByCondition;
    }

    //确认更改员工信息
    @ResponseBody
    @RequestMapping("/staffUpdate")
    public Boolean staffUpdate(@RequestBody TbStaff staff,HttpSession session){
        TbStaff tbStaff =(TbStaff)session.getAttribute("loginUser");
        staff.setId(tbStaff.getId());
        staff.setStaffStatus(1);
        return personalInfoService.updateStaffInfo(staff)>0;
    }

    //确认更改员工密码
    @ResponseBody
    @RequestMapping("/staffPwdUpdate")
    public Boolean staffPwdUpdate(@RequestBody TbStaff staff,HttpSession session){
        TbStaff tbStaff =(TbStaff)session.getAttribute("loginUser");
        staff.setId(tbStaff.getId());
        return personalInfoService.updateStaffPassword(staff)>0;
//        return true;
    }

    //检查邮箱是否存在
    @ResponseBody
    @RequestMapping("/checkEmail")
    public TbStaff checkEmail(@RequestBody TbStaff staff,HttpSession session){
        TbStaff tbStaff =(TbStaff)session.getAttribute("loginUser");
        staff.setId(tbStaff.getId());
        return personalInfoService.checkEmail(staff);
    }

    //检查电话号码是否存在
    @ResponseBody
    @RequestMapping("/checkTel")
    public TbStaff checkTel(@RequestBody TbStaff staff,HttpSession session){
        TbStaff tbStaff =(TbStaff)session.getAttribute("loginUser");
        staff.setId(tbStaff.getId());
        return personalInfoService.checkTel(staff);
    }

    //检查员工号是否存在
    @ResponseBody
    @RequestMapping("/checkStaffId")
    public TbStaff checkStaffId(@RequestBody TbStaff staff,HttpSession session){
        TbStaff tbStaff =(TbStaff)session.getAttribute("loginUser");
        staff.setId(tbStaff.getId());
        return personalInfoService.checkStaffId(staff);
    }

}
